<%-- 
    Document   : accountbalances
    Created on : Dec 6, 2012, 9:11:10 PM
    Author     : Quang Nhat
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Account Balance</title>
        <script type="text/javascript">
            function validDate(txt) {
                var parts = txt.split("/");
                if (parts.length != 3) {
                    return false;
                }
                var date = new Date(parts[2], parts[1] - 1, parts[0]);
                return (date != "Invalid Date");
            }
            function valid() {
                var txtDate = document.getElementById("txtDate").value;
                if (!validDate(txtDate)) {
                    alert("Invalid Date.");
                    return false;
                }
                return true;
            }
            function init() {
                var btnExport = document.getElementById("btnExport");
                btnExport.href+= "&txtDate" + document.getElementById("txtDate").value;
            }
        </script>
    </head>
    <body onload="init();">
        <%@include file="/WEB-INF/jspf/Header.jspf" %>
        <h1>Account Balances at ${requestScope.date.date}/${requestScope.date.month + 1}/${requestScope.date.year + 1900}</h1>
        <form action="Accountant" class="form" style="overflow: hidden;width:220px" onsubmit="return valid();">
            <div><label>Date: <input id="txtDate" type="text" name="txtDate" value="${requestScope.date.date}/${requestScope.date.month + 1}/${requestScope.date.year + 1900}" /></label></div>
            <div class="form-control">
                <input type="hidden" name="action" value="accountBalances" />
                <input type="submit" value="Get" />
            </div>
        </form>
        <a id="btnExport" href="Accountant?action=pdfAccountBalances" class="button" style="text-decoration: none; clear: both; float: left; height: 18px;margin-bottom: 10px; margin-left: 20px; font-size: 14px">Export to PDF</a>
        <table border="1" id="accountBalances">
            <thead>
                <tr>
                    <th>Account</th>
                    <th>Debit</th>
                    <th>Credit</th>
                </tr>
            </thead>
            <tbody>
                <c:set var="balances" value="${requestScope.balances}"/>
                <c:forEach var="bal" items="${balances}">
                    <tr>
                        <td>${bal.accountNumber} - ${bal.accountName}</td>
                        <td>
                            <c:if test="${bal.isDebit}">
                                ${bal.balance}
                            </c:if>
                        </td>
                        <td>
                            <c:if test="${not bal.isDebit}">
                                ${bal.balance}
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </body>
</html>
